package cn.ycl.system.other.study.designMode.combination;

import lombok.Data;
import lombok.ToString;

/**
 * @author YuanChangLiang
 * @description
 * @date created in 14:16 2021/5/31
 */

@Data
@ToString
public class Animal implements Cloneable {
    private String name;

    private Monkey monkey;

    @Override
    public Animal clone(){
        Animal animal = null;
        try {
            //直接调用父类的clone方法，只能clone基本类型数据（包括String和基本数据类型封装类）
            animal = (Animal) super.clone();
            //需要调用深层次clone
            animal.setMonkey((Monkey) this.monkey.clone());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return animal;
    }


}
